package adebo.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import javax.sql.DataSource;

import org.apache.commons.dbcp.BasicDataSource;

public class DriverManagerDAOFactory extends DAOFactory {
	private final String url;
	private final String username;
	private final String password;
	private final String dbname;
	private final String driver;

	DriverManagerDAOFactory(String url, String username, String password, String dbname,String driver) {
		this.url = url;
		this.username = username;
		this.password = password;
		this.dbname = dbname;
		this.driver = driver;
	}

	@Override
	public	Connection getConnection() throws SQLException {
		Connection con = DriverManager.getConnection(url, username, password);
		con.setCatalog(dbname);
		
		return con;
	}
	
	@Override
	public DataSource setupDataSource() {
        BasicDataSource ds = new BasicDataSource();
        ds.setDriverClassName(driver);
        ds.setUsername(username);
        ds.setPassword(password);
        ds.setUrl(url);
        ds.setDefaultCatalog(dbname);
        return ds;
    }

	

}
